import { storage } from '../util/wx-mini'

/**
 * 生成浏览器缓存数据
 *
 * @export
 */
export default function userId(dataKey) {
	try {
		let gid = storage(dataKey)
		if (gid && gid != 'undefined') {
			return gid
		}
		gid = new Date().getTime().toString(36) + Math.random().toString().substr(2, 6)
		storage(dataKey, gid)
		return gid
	} catch (e) {
		console.error(e)
	}
}


/**
 * 
 *   let data:any = {}
  const bData = bowerData();
  if (!bData) return;
  // 事件时间
  data.at = data.at || new Date().getTime();
  // 随机id
  data.gid = bData;
  // 环境
  data.env = env;
  // 系统
  data.ue = userBase.ue;
  data.os = userBase.os;
  // 路由
  data.url = data.url || window.location.href.replace(window.location.origin, '');
  const extra = (window as any).Moon.extra;
  if (typeName(extra) === 'function') {
    data = (window as any).Moon.extra(data)
  }else if (typeName(extra) === 'array') {
    data.extra = extra;
  }else if ((window as any).Moon.extra) {
    data = {
      ...data,
      ...extra,
    }
  }
  return data;

  */